# -*- coding: utf-8 -*-

#   Copyright (C) 2011  P.L. Lucas
#
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.


# Cleans subversion files

import os, sys
import os.path
import filecmp
from stat import *

if len(sys.argv)<2 or sys.argv[1]=='--help':
	print """
	Cleans subversion files
	
	python clean.py directorio
	"""
	exit(0)

def list_dirs(path, solamente_dirs_ok=True):
	l=[]
	for f in os.listdir(path):
		pathname = os.path.join(path, f)
		mode = os.stat(pathname)[ST_MODE]
		if S_ISDIR(mode):
			# It's a directory, recurse into it
			a=list_dirs(pathname, solamente_dirs_ok)
			if solamente_dirs_ok:
				l.append(pathname)
			for x in a:
				l.append(x)
		elif not solamente_dirs_ok:
		    # It's a file
		    l.append(pathname)
	return l

dirs=list_dirs(sys.argv[1])
for x in dirs:
	if x.find('/.svn')!=-1:
		print 'rm -Rf "{0}"'.format(x)